function status = leapy(y)
% leapy - search of leap years
%
%       STATUS = leapy(YEAR)
%
% Let YEAR be a year vector (Common Era). The logical output STATUS(k) is 
% true if YEAR(k) is a leap year, false otherwise.
% If YEAR is not an integer vector, fix(YEAR) is used.
% Leap year condition considere here:
% - if YEAR(k) >= 1582, year of Gregorian reform, the condition is multiple 
%   of 4 with the constrain that this is not the first year of a century 
%   not multiple of 400 (for example, 2000 is a leap year, 1900 not);
% - if YEAR(k) < 1582, i.e. the Julian calendar is used, the condition is, 
%   simply, multiple of 4, in accordance with the reform by Ceasar Octavian 
%   Augustus (please note that there is no agreement about the leap years
%   in the period between the introduction of Julian Calendar and the
%   Octavian's reform. Therefore, results for BCE dates are meaningless).

% G. Teza, 2021

y = fix(y);

I4 = mod(y,4) == 0;         % multiple of 4: leap year candidate 
Iv = not(mod(y,100) == 0) | (mod(y,400) == 0); % false if y is a first year
                            % of a century not multiple of 400 
Iv(y < 1582) = true;        % reset of Gregorian conditions before 1582                          

status = I4&Iv;